package BuyerAgent;

import java.util.ArrayList;

import javax.swing.table.AbstractTableModel;

/**
 * This class is the model table for the wish list table in buyer GUI
 * 
 * @author DUY HAN PHAN
 */
public class WishListModelTable extends AbstractTableModel {
	// Each value in the array is a row; ArrayList<Object> - row data;
	private ArrayList<ArrayList<Object>> data = new ArrayList<ArrayList<Object>>();
	private ArrayList<String> columnNames = new ArrayList<String>();

	public WishListModelTable(ArrayList<Tree> wishListTrees) {
		super();
		columnNames.add("Common Name");
		columnNames.add("Latin Name");
		columnNames.add("Category");
		columnNames.add("Quantity");

		for (int i = 0; i < wishListTrees.size(); i++) {
			Tree tree = wishListTrees.get(i);
			ArrayList<Object> tmp = new ArrayList<>();
			tmp.add(tree.getCommonName());
			tmp.add(tree.getLatinName());
			tmp.add(tree.getCategory());
			tmp.add(tree.getQuantity());
			this.data.add(tmp);
		}
	}

	@Override
	public int getColumnCount() {
		return columnNames.size();
	}

	@Override
	public String getColumnName(int column) {
		return columnNames.get(column);
	}

	@Override
	public int getRowCount() {
		return data.size();
	}

	@Override
	public Object getValueAt(int rowIndex, int columnIndex) {
		return data.get(rowIndex).get(columnIndex);
	}

	public void removeRow(int row) {
		data.remove(row);
	}

}
